package com.luiz.aero.android.computation;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Date;

import android.os.Environment;

import com.luiz.aero.android.data.Position;
import com.luiz.aero.android.data.Route;

public class Recorder {

	BufferedWriter bw;
	File folder = null;
	String path;

	public Recorder() {
		path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/AeroArduino/logs";
		File folder = new File(path);
		if(!folder.exists()){
			folder.mkdir();
		}
	}

	public void recordRoute(Route route) throws IOException{

		String filePath = path + "record" + new Date().getTime() + ".txt";
		bw = new BufferedWriter(new FileWriter(new File(filePath), true));

		for(Position pos: route.getRoute()){
			String position = pos.toString();
			bw.write(position);
			bw.newLine();
		}
		bw.close();
	}
}
